import { getPorts, connectPort } from '@/api/ljsz'
import { connectPortcld, connectPorthx, connectPortwrj } from '../../../../api/ljsz'
export default {
  data() {
    return {
      setTimeForm: {
        wrjPort: 'COM42',
        hxjPort: 'COM43',
        cldPort: 'COM36'
      },
      // 测量点 、航向 、无人机下拉列表数据
      selectOptions: [
        'COM36',
        'COM37',
        'COM38',
        'COM39',
        'COM40',
        'COM41',
        'COM42',
        'COM43'
      ],
      setTimeRules: {}
    }
  },
  created() {},
  mounted() {
    this.getSelectPorts()
  },
  methods: {
    /**
     * 获取所以已打的串口
     */
    getSelectPorts() {

        getPorts().then(res => {
          if (res.code === 0) {
            this.selectOptions = res.data
          } else {
            this.$message.error(res.message)
          }
        })

    },
    /**
     * 开始连接 按钮事件
     */
    startClick() {
      // console.log('setTimeForm', this.setTimeForm)
      const params = {
        wrjPort: this.setTimeForm.wrjPort,
        hxPort: this.setTimeForm.hxjPort,
        cldPort: this.setTimeForm.cldPort
      }
      console.log('setTimeForm', params)
      connectPort(params).then(res => {
        if (res.code === 0) {
          this.$message.success('连接成功!')
        } else {
          this.$message.error('连接失败!')
        }
      })
    },
    startClickwrj() {
      // console.log('setTimeForm', this.setTimeForm)
      const params = {
        wrjPort: this.setTimeForm.wrjPort

      }
      console.log('setTimeForm', params)
      connectPortwrj(params).then(res => {
        if (res.code === 0) {
          this.$message.success('连接成功!')
        } else {
          this.$message.error('连接失败!')
        }
      })
    },
    startClickcld() {
      // console.log('setTimeForm', this.setTimeForm)
      const params = {
        // wrjPort: this.setTimeForm.wrjPort,
        // hxPort: this.setTimeForm.hxjPort,
        cldPort: this.setTimeForm.cldPort
      }
      console.log('setTimeForm', params)
      connectPortcld(params).then(res => {
        if (res.code === 0) {
          this.$message.success('连接成功!')
        } else {
          this.$message.error('连接失败!')
        }
      })
    },
    startClickhx() {
      // console.log('setTimeForm', this.setTimeForm)
      const params = {

        hxPort: this.setTimeForm.hxjPort
      }
      console.log('setTimeForm', params)
      connectPorthx(params).then(res => {
        if (res.code === 0) {
          this.$message.success('连接成功!')
        } else {
          this.$message.error('连接失败!')
        }
      })
    }
  }
}
